package projectEuler;

public class Problem_04 {
        public static void main(String args[]){
                int num =  998001;
                int finalNum = 0;
                do{
                        System.out.println(num);
                        if(isPalindrome(num)){
                                if(findFactors(num)){
                                        finalNum = num;
                                }
                        }
                        num--;
                }while(finalNum == 0);
                System.out.println(finalNum);
        }
        public int arrayToInt(int number[]){
                int sum = 0;
                for(int count = 0; count < number.length; count++){
                        sum = sum*10 + number[count];
                }
                return sum;
        }
        public static boolean findFactors(int number){
                for(int count = 999; count > 99; count--){
                        if(number%count == 0&&number/count > 99&&number/count<1000){
                                System.out.println(count);
                                return true;
                        }
                }
                return false;
        }
        public static boolean isPalindrome(int innum){
                int num = innum;
                int number[] = new int[10];
                int slider = -1;
                do{
                        slider++;
                        number[slider] = num%10;
                        num = num - num%10;
                        num= num/10;
                }while(num != 0);
                for(int slider2 = 0; slider2<= slider; slider2++){
                        if(number[slider] != number[slider2]){
                                System.out.println(number[slider]+" != "+number[slider2]);
                                return false;
                        }
                        slider--;
                }
                return true;
        }
}